<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../includes/common.jsp" %>

<form action="${scriptPath}" id="form_edit">
    <input type="hidden" name="action" value="exam.edit" />
    <input type="hidden" name="ee_id" value="${exam.id}" />

    <p><label>Tên: 
        <input type="text" name="ee_name" 
                value="${u:defaultIfNull(param.ee_name, exam.name)}">
                </input></label> 
        <c:if test="${!(empty nameErr)}">
            <span style="color:red">${nameErr}</span>
        </c:if>
    </p>
    <br></br>
    
    <p><label>Lớp: 
        <input type="text" name="ee_class" 
                value="${u:defaultIfNull(param.ee_class, exam.clazz)}">
                </input></label> 
        <c:if test="${!(empty classErr)}">
            <span style="color:red">${classErr}</span>
        </c:if>
    </p>
    <br></br>
    
    <p><label>Đề thi:
       <input type="text" name="ee_testname" 
            value="${u:defaultIfNull(param.ee_testname, exam.test.name)}" 
            id="txtTest"></input>
       <input type="hidden" name="ee_testid" 
            value="${u:defaultIfNull(param.ee_testid, exam.test.id)}" 
            id="valTest"></input>
    </label>
    </p>
    <br></br>
    
    <p>
        <button type="submit" name="ee_submit" value="save">Lưu</button>
        <button type="button" onclick="location.href='${scriptPath}?action=exam.view&ev_id=${exam.id}'">Thôi</button>
    </p>
</form>

<script type="text/javascript">
  new Autocomplete('txtTest', { 
      serviceUrl:'${scriptPath}?action=test.ajaxsearch',    
      minChars:2, 
      maxHeight:400,
      width:300,
      deferRequestBy:100,
      // callback function:
      onSelect: function(value, data){
          $('valTest').value = data;
      }
    });
</script>